import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import http from './utils/http'
import '@/assets/style/normalize.css'
import dayis from 'dayjs'

Vue.use(ElementUI)

Vue.prototype.$http = http(router, store)
Vue.prototype.$baseUrl = 'http://api.aiyund.top'
Vue.prototype.$dateFormat = function(date) {
  return dayis(date).format('YYYY-MM-DD')
}

Vue.config.productionTip = false

const whiteList = ['/login', '/register']
router.beforeEach((to, from, next) => {
  const token = store.state.token
  if (whiteList.indexOf(to.path) < 0) {
    if (token) {
      next()
    } else {
      next({ path: '/login' })
    }
  } else {
    next()
  }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
